﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Mesuro.Graphing.Utilities;

namespace Mesuro.Graphing.PropertiesControls {
	/// <summary>
	/// Interaction logic for LinePlotProperties.xaml
	/// </summary>
	public partial class MeshMapProperties : PlotProperties {

		#region DP: MinColor
		public static readonly DependencyProperty MinColorProperty = DependencyProperty.RegisterAttached( "MinColor", typeof( Color ), typeof( MeshMapProperties ), new FrameworkPropertyMetadata( Colors.Green, FrameworkPropertyMetadataOptions.None, MinColorChangedStatic ) );
		public Color MinColor {
			get { return (Color)GetValue( MinColorProperty ); }
			set { SetValue( MinColorProperty, value ); }
		}
		public static Color GetMinColor( DependencyObject element ) { return (Color)element.GetValue( MinColorProperty ); }
		public static void SetMinColor( DependencyObject element, Color value ) { element.SetValue( MinColorProperty, value ); }
		private static void MinColorChangedStatic( DependencyObject sender, DependencyPropertyChangedEventArgs e ) {
			ReCalcCoefficients( sender );
		}
		#endregion

		#region DP: MaxColor
		public static readonly DependencyProperty MaxColorProperty = DependencyProperty.RegisterAttached( "MaxColor", typeof( Color ), typeof( MeshMapProperties ), new FrameworkPropertyMetadata( Colors.Red, FrameworkPropertyMetadataOptions.None, MaxColorChangedStatic ) );
		public Color MaxColor {
			get { return (Color)GetValue( MaxColorProperty ); }
			set { SetValue( MaxColorProperty, value ); }
		}
		public static Color GetMaxColor( DependencyObject element ) { return (Color)element.GetValue( MaxColorProperty ); }
		public static void SetMaxColor( DependencyObject element, Color value ) { element.SetValue( MaxColorProperty, value ); }
		private static void MaxColorChangedStatic( DependencyObject sender, DependencyPropertyChangedEventArgs e ) {
			ReCalcCoefficients( sender );
		}
		#endregion

		#region DP: Coefficients
		public static readonly DependencyProperty CoefficientsProperty = DependencyProperty.RegisterAttached( "Coefficients", typeof( Color ), typeof( MeshMapProperties ), new FrameworkPropertyMetadata( Colors.Red, FrameworkPropertyMetadataOptions.None, CoefficientsChangedStatic ) );
		public Color Coefficients {
			get { return (Color)GetValue( CoefficientsProperty ); }
			set { SetValue( CoefficientsProperty, value ); }
		}
		public static Color GetCoefficients( DependencyObject element ) { return (Color)element.GetValue( CoefficientsProperty ); }
		public static void SetCoefficients( DependencyObject element, Color value ) { element.SetValue( CoefficientsProperty, value ); }
		private static void CoefficientsChangedStatic( DependencyObject sender, DependencyPropertyChangedEventArgs e ) { }
		#endregion

		private static void ReCalcCoefficients( DependencyObject sender ) {
			Color Max = GetMaxColor( sender );
			Color Min = GetMinColor( sender );
			SetCoefficients( sender, Color.FromArgb(
				(byte)(127 + 0.5 * (Max.A - Min.A)),
				(byte)(127 + 0.5 * (Max.R - Min.R)),
				(byte)(127 + 0.5 * (Max.G - Min.G)),
				(byte)(127 + 0.5 * (Max.B - Min.B))
				) );
		}

		public MeshMapProperties() {
			InitializeComponent();
		}
	}
}
